<%@page import="java.util.ArrayList"%>
<%@ include file="/init.jsp"%>


<%@page import="java.util.StringTokenizer"%>
<%@page import="com.liferay.portal.service.ListTypeServiceUtil"%>
<%@page import="com.liferay.portal.model.ListType"%>
<%@ include file="/init.jsp"%>
<script src="<%=request.getContextPath()%>/js/jquery-1.6.2.js" language="javascript" type="text/javascript"></script>
<portlet:resourceURL var="ajaxCallResourceURL" />

<%
ListType mappedFee = (ListType) request.getAttribute("mappedFee");
System.out.println("doing ID >>>" + mappedFee.getListTypeId());

List<ListType> mappedSubFees = 
	ListTypeServiceUtil.getListTypes
		("com.teqbridgeltd.liferay.model.map.Fees." + mappedFee.getName() );
System.out.println("com.teqbridgeltd.liferay.model.map.Fees." + mappedFee.getName() +"<<<");

%>
		<aui:layout>
			<aui:column>
				<span class="hder" id="feesName_<%=mappedFee.getListTypeId() %>" ><%=mappedFee.getName() %></span>
			</aui:column>
		</aui:layout>
 		
 		
 		<aui:layout>
			<aui:column columnWidth="33">
				<%
				List<ListType> layoutName = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.layout");
				%>
			
				<strong>Zone/Layout</strong>
				<select  disabled="disabled" id="layout_<%=mappedFee.getListTypeId() %>" name="layout_<%=mappedFee.getListTypeId() %>" label="" >
				<option style="font-style: italic; color: #A0A0A4" value="">--Please Select Layout--</option>
		  	
			  	<%
			  	for(int i=0; i<layoutName.size(); i++){ ListType _layoutName = layoutName.get(i);
			  	%>	
		  		<aui:option  value="<%=_layoutName.getName() %>"><%=_layoutName.getName()  %></aui:option>
			  	<%
			  	}
			  	%>
				</select>
			</aui:column>
			<aui:column columnWidth="33">
				<%
				List<ListType> useTypes = ListTypeServiceUtil.getListTypes("com.teqbridgeltd.liferay.model.land_use");
				%>
				<aui:select name="useTypeDevLevy" label="Specify Required Land Use">
					<option value="">-Please Select Land Use-</option>
			  	
			  	<%
			  	for(int i=0; i<useTypes.size(); i++){
			  		ListType _useType = useTypes.get(i);
			  	%>	
			  	<aui:option value="<%=_useType.getName() %>"><%=_useType.getName()  %></aui:option>
			  	<%
			  	}
			  	%>
				</aui:select>
			</aui:column>
			<aui:column columnWidth="33"><br>
				&nbsp;
			</aui:column>
		</aui:layout>
		
		<aui:layout>
			<aui:column columnWidth="33">
				&nbsp;
			</aui:column>
			<aui:column columnWidth="33"><br>
				<strong>Area (Sq Meters):</strong>
				<input readonly="readonly" id="area_<%=mappedFee.getListTypeId() %>"  name="area_<%=mappedFee.getListTypeId() %>" type="text"></input>
			</aui:column>
			<aui:column columnWidth="33"><br><br>
				<input readonly="readonly" name="result_<%=mappedFee.getListTypeId() %>"  id="result_<%=mappedFee.getListTypeId() %>" type="text" value="" class="resultbox">
			</aui:column>
		</aui:layout>
 		
		<aui:layout>
			<aui:column>
				<button type="button" onclick="ComputeFee_<%=mappedFee.getListTypeId() %>();" name="compute_result" value="Compute">Compute</button>
			</aui:column>
		</aui:layout>

 
 <portlet:resourceURL var="fetchdataAction">
</portlet:resourceURL>

<script>
function ComputeFee_<%=mappedFee.getListTypeId() %>(){
	try{
		var result = document.getElementById('result_<%=mappedFee.getListTypeId() %>');
		var layout = document.getElementById('layout_<%=mappedFee.getListTypeId() %>');
		var useType = document.getElementById('<portlet:namespace/>useTypeDevLevy');
		var area = document.getElementById('area_<%=mappedFee.getListTypeId() %>');
		hidePrintButton();
		
		var propertyType_Fixed = document.getElementById('<portlet:namespace/>propertyType_Fixed');
		if(propertyType_Fixed.value == 'Private'){
			alert('No Premium Fees for Private Land');
			result.value=0;
		}else{
			fn_getDevLevyRate(layout.value, useType.value, area.value );
			computeTotal();
		}
		
	}catch(err){
	  txt="There was an error on this page.\n\n";
	  err.message
	  txt+="Error description: " + err.description + "\n\n";
	  txt+="Click OK to continue.\n\n";
	  txt+=err.message + "\n\n";
	  alert(txt);
	}
	
}


function fn_getDevLevyRate(layout, useType, area )
{
    $.ajax({
       type: "POST",
       url: "<%= fetchdataAction %>",
       data: {
    	   <portlet:namespace />layout: layout,
			<portlet:namespace />useType: useType,
			<portlet:namespace />area: area,
			<portlet:namespace />queryType: 'getDevLevyRate',
		},
		dataType: "json",
       success: function(msg){

    	var message = msg;
    						
    	var penalty = message.penalty;
		var groundRent = message.groundRent;
		
		
		if(message){
			document.getElementById('result_<%=mappedFee.getListTypeId() %>').value=message.devLevy;
		}else {
			alert('no data back from server');
		}
		
       }
     });
}

</script>


<aui:script>
	Liferay.provide(window,
		'fn_getDevLevyRateOLD',
		function(layout, useType, area ) {
	
			var A = AUI();
			//alert('in fn_getDevLevyRate');
			var url = '<%= ajaxCallResourceURL.toString() %>';
				A.io.request(
					url,
					{
						//data to be sent to server
						data: {
							<portlet:namespace />layout: layout,
							<portlet:namespace />useType: useType,
							<portlet:namespace />area: area,
							<portlet:namespace />queryType: 'getDevLevyRate',
							
						},
						dataType: 'json',

						on: {
							failure: function() {
							},

							success: function(event, id, obj) {
								var instance = this;


								//JSON Data coming back from Server
								
								var message = instance.get('responseData');
								
								if(message){
									document.getElementById('result_<%=mappedFee.getListTypeId() %>').value=message.devLevy;
								}else {
									alert('no data back from server');
								}
							}

						}
					}

				); //END of io Request

		},
		['aui-io']
	);  //End of Provide
	
</aui:script>
